/********************************************************************************
 *      Copyright:  (C) 2021 iot
 *                  All rights reserved.
 *
 *       Filename:  util_proc.h
 *    Description:  This head file 
 *
 *        Version:  1.0.0
 *         Author:  mk
 *                 
 ********************************************************************************/

#ifndef _UTIL_PROC_H_
#define _UTIL_PROC_H_

#include <signal.h>

#define PID_ASCII_SIZE  11

typedef struct proc_signal_s
{
    int       signal;
    unsigned  stop;     /*  0: Not term  1: Stop  */
}  proc_signal_t;

typedef void *(* thread_body_t) (void *thread_arg);

extern proc_signal_t    g_signal;

/*  install default signal process functions  */
extern void install_default_signal(void);

/*  excute a linux command by system() */
extern void exec_system_cmd(const char *format, ...);

/*  check program already running or not from $pid_file  */
extern int check_daemon_running(const char *pid_file);

/*  set program daemon running and record pid in $pid_file  */
extern int set_daemon_running(const char *pid_file);

/*  record proces ID into $pid_file  */
extern int record_daemon_pid(const char *pid_file);

/*  stop program running from $pid_file  */
extern int stop_daemon_running(const char *pid_file);

/*  start a new thread to run $thread_workbody point function  */
extern int thread_start(pthread_t *thread_id, thread_body_t thread_workbody, void *thread_arg);

/*  +---------------------+
 * |   Low level API     |
 * +---------------------+*/

/*  get daemon process ID from $pid_file   */
extern pid_t get_daemon_pid(const char *pid_file);


#endif

